<?php
	session_start();
	function is_admin(){
		if ($_SESSION['type'] == 'coordinator'){
			return true;
		} else {
			// Send to someplace else for right now
			header('Location: index.php');
		}
	}	
	
	function is_leader(){
		if ($_SESSION['type'] == 'leader'){
			return true;
		} else {
			// Send to someplace else for right now
			header('Location: index.php');
		}
	}
	
	function is_leader_of_midweek($midweekLeader1, $midweekLeader2){
		if ($_SESSION['type'] == 'coordinator' || $_SESSION['ID'] == $midweekLeader1 || $_SESSION['ID'] == $midweekLeader2 )		    {
			return true;
		} else {
			// Send to someplace else for right now
			return false;
		}
	}
	
	function is_either(){
		if($_SESSION['type'] == 'leader' || $_SESSION['type'] == 'admin'){
			return true;
		} else {
			// Send to someplace else for right now
			header('Location: index.php');
		}
	}
	
	function is_logged_in(){
		if (!session_is_registered('ID')) :
			header('Location: login.php');
		endif;
	}
	
	function checkPhone($var,$midweekNameOld){
		$dontadd = 0;
		if(strcmp($var,"")!=0){
			$var = trim($var);
			if(strcmp(substr($var,0,1),"(")==0){
				if(strcmp(substr($var,4,1),")")==0){
					if(ctype_digit(substr($var,1,3))){			
						if(strcmp(substr($var,8,1),"-")==0){
							if(ctype_digit(substr($var,5,3)) && ctype_digit(substr($var,9,4))){
							} else { 
								header('Location: midweekpage.php?midweek_name='.$midweekNameOld.'&error=1'); 
								$dontadd=1;
								}
						} else { 
							header('Location: midweekpage.php?midweek_name='.$midweekNameOld.'&error=1'); 
							$dontadd=1;
						}
					} else { 
						header('Location: midweekpage.php?midweek_name='.$midweekNameOld.'&error=1'); 
						$dontadd=1;
					}
				} else { 
					header('Location: midweekpage.php?midweek_name='.$midweekNameOld.'&error=1'); 
					$dontadd=1;
				}
			} else if (strcmp(substr($var,3,1),"-")==0 && strcmp(substr($var,7,1),"-")==0){
				if(!(ctype_digit(substr($var,0,3)) && ctype_digit(substr($var,4,3)) && ctype_digit(substr($var,8,4)))){
					header('Location: midweekpage.php?midweek_name='.$midweekNameOld.'&error=1'); 
					$dontadd=1;
				}
			} else if (!(ctype_digit($var) && (strlen($var)==10))){
				header('Location: midweekpage.php?midweek_name='.$midweekNameOld.'&error=1');  
				$dontadd=1;
			}
		}
		return $dontadd;
	}
	
?>
